<!DOCTYPE html>
<!--[if IE 8]> <html lang="zh-CN" class="ie8"> <![endif]-->
<html lang="zh-CN">

<head>
	<link rel="shortcut icon" href="https://www.itsource.cn/img/logo_small.jpg">
	<meta charset="utf-8" />
	<title>登录 - 用户中心</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link type="text/css" rel="stylesheet" href="css/common.css">
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/login.js"></script>
	<link type="text/css" rel="stylesheet" href="css/login.css">
	<link type="text/css" rel="stylesheet" href="css/color-style.css" />
	<script type="text/javascript" src="js/layer.js"></script>
	<script type="text/javascript" src="js/jquery.method.js"></script>
	<script type="text/javascript" src="js/placeholder.js"></script>
	<script type="text/javascript" src="js/jquery.supersized.min.js"></script>

	<script type="text/javascript" src="js/plugins/vue/dist/vue.js"></script>
	<script type="text/javascript" src="js/plugins/axios/dist/axios.js"></script>
	<script src="js/jquery.cookie.js"></script>
	<link rel="stylesheet" href="js/jqueryAlert/alert.css">
	<script src="js/jqueryAlert/alert.js"></script>
</head>

<body>
<div class="header login-header w990">
	<div class="logo-info">


	</div>
</div>
<div class="login-content">
		<div class="w990 pos-r">

			<div id="14849678895bBEJL" class="login-form">
				<div class="login-con pos-r">






						<!-- 普通登录 star -->

						<div id="con_login_2" class="form">
							<form id="form2" action="http://user.ymcc.com:6003/login.html" method="POST">
								<input type="hidden" name="_csrf" value="X3YzS2VmZWoHDlt8IR4uEwo.bBRWMww8CS4GDFQ3MBBnMnQECyldHQ==">
								<div class="form-group item-name">
									<!-- 错误项标注 给div另添加一个class值'error' star -->
									<div class="form-control-box">
										<i class="icon"></i>
										<input type="text" v-model="formParams.phone" id="username" name="LoginModel[username]" value="" class="text" tabindex="1" placeholder="已验证手机/邮箱/用户名" autocomplete="off" />
									</div>

									<!-- 错误项标注 给div另添加一个class值'error' end -->
								</div>
								<div class="form-group item-password">
									<div class="form-control-box">
										<i class="icon"></i>
										<input type="password" v-model="formParams.password" id="password" name="LoginModel[password]" value="" class="text" tabindex="2" placeholder="密码" autocomplete="off" />
									</div>

								</div>


								<div class="login-btn">
									<input type="hidden" name="act" value="act_login" />
									<input type="hidden" name="back_act" value="" />
									<input type="button" @click="submitLogin" name="submit" class="btn-img btn-entry bg-color" id="loginsubmit" value="完成检测" />
								</div>
								<div class="item-coagent">

									<a href="javascript:void(0);" data-id="pc_weixin" class="website-login">
										<i class="weixin"></i>
									</a>

									<a href="javascript:void(0);" data-id="qq" class="website-login">
										<i class="qq"></i>
									</a>

									<a href="javascript:void(0);" data-id="weibo" class="last website-login">
										<i class="sina"></i>
									</a>

								</div>
								<input type="hidden" name="back_url" value="http://user.ymcc.com/register/mobile.html" />

							</form>
						</div>
						<!-- 普通登录 end -->
						<!-- 动态登录 star -->

						<div id="con_login_1" class="form" style="display: none;">
							<form id="form1" action="http://user.ymcc.com:6003/login.html" method="POST">
								<input type="hidden" name="_csrf" value="X3YzS2VmZWoHDlt8IR4uEwo.bBRWMww8CS4GDFQ3MBBnMnQECyldHQ==">
								<div class="form-group item-name">
									<!-- 错误项标注 给div另添加一个class值'error' star -->
									<div class="form-control-box">
										<i class="icon"></i>
										<input type="text" id="mobile" name="SmsLoginModel[mobile]" class="text" value="" tabindex="1" placeholder="已注册的手机号码" autocomplete="off" />
									</div>

									<!-- 错误项标注 给div另添加一个class值'error' end -->
								</div>

								<div class="form-group form-group-spe captcha" id="o-authcode">
									<div class="form-control-box">
										<i class="icon"></i>
										<input type="text" id="captcha_sms" name="SmsLoginModel[captcha]" class="text" tabindex="2" placeholder="验证码" />
										<label class="captcha"> <img id="captcha_sms-image" class="captcha-image" src="img/captcha.html" alt="点击换图" title="点击换图" style="vertical-align: middle; cursor: pointer;"><script data-captcha-id='captcha_sms-image' type='text'>{"refreshUrl":"\/site\/captcha.html?refresh=1","hashKey":"niiCaptcha\/site\/captcha"}</script></label>
									</div>

								</div>

								<div class="form-group form-group-spe form-group-phonecode">
									<div class="form-control-box fl">
										<i class="icon"></i>
										<input type="text" id="smsCaptcha" name="SmsLoginModel[smsCaptcha]" class="text" tabindex="3" placeholder="动态密码" />
										<a id="btn_send_sms_code" href="javascript:void(0);" class="phonecode">获取手机动态验证码</a>
									</div>

								</div>



								<div class="login-btn">
									<input type="hidden" name="act" value="act_login" />
									<input type="hidden" name="back_act" value="" />
<!--									<input type="submit" name="submit" class="btn-img btn-entry bg-color" id="loginsubmit" value="立即登录" />-->
								</div>
								<div class="item-coagent">

									<a href="javascript:void(0);" data-id="qq" class="website-login">
										<i class="qq"></i>
									</a>

									<a href="javascript:void(0);" data-id="pc_weixin" class="website-login">
										<i class="weixin"></i>
									</a>

									<a href="javascript:void(0);" data-id="weibo" class="last website-login">
										<i class="sina"></i>
									</a>

								</div>
								<input type="hidden" name="back_url" value="http://user.ymcc.com/register/mobile.html" />

							</form>
						</div>
						<!-- 动态登录 end -->
					</div>

				</div>
			</div>

			<!-- 验证码脚本 -->
			<script type="text/javascript" src="js/jquery.captcha.js"></script>
			<!-- 表单验证 -->
			<script type="text/javascript" src="js/jquery.validate.js"></script>
			<script type="text/javascript" src="js/jquery.validate.custom.js"></script>
			<script type="text/javascript" src="js/messages_zh.js"></script>
			<script id="client_rules" type="text/javascript">
				[{
					"id": "loginmodel-username",
					"name": "LoginModel[username]",
					"attribute": "username",
					"rules": {
						"required": true,
						"messages": {
							"required": "请输入用户名"
						}
					}
				}, {
					"id": "loginmodel-password",
					"name": "LoginModel[password]",
					"attribute": "password",
					"rules": {
						"required": true,
						"messages": {
							"required": "请输入密码"
						}
					}
				}, {
					"id": "loginmodel-username",
					"name": "LoginModel[username]",
					"attribute": "username",
					"rules": {
						"string": true,
						"messages": {
							"string": "用户名必须是一条字符串。",
							"maxlength": "用户名长度必需在100以内"
						},
						"maxlength": 50
					}
				}, {
					"id": "loginmodel-password",
					"name": "LoginModel[password]",
					"attribute": "password",
					"rules": {
						"string": true,
						"messages": {
							"string": "密码必须是一条字符串。",
							"maxlength": "密码长度必需在32以内"
						},
						"maxlength": 32
					}
				}, {
					"id": "loginmodel-rememberme",
					"name": "LoginModel[rememberMe]",
					"attribute": "rememberMe",
					"rules": {
						"boolean": {
							"trueValue": "1",
							"falseValue": "0"
						},
						"message": {
							"boolean": "记住用户名密码的值必须要么为\"1\"，要么为\"0\"。"
						}
					}
				}, ]
			</script>
			<script id="sms_client_rules" type="text/javascript">
				[{
					"id": "smsloginmodel-mobile",
					"name": "SmsLoginModel[mobile]",
					"attribute": "mobile",
					"rules": {
						"required": true,
						"messages": {
							"required": "请输入手机号码"
						}
					}
				}, {
					"id": "smsloginmodel-smscaptcha",
					"name": "SmsLoginModel[smsCaptcha]",
					"attribute": "smsCaptcha",
					"rules": {
						"required": true,
						"messages": {
							"required": "请输入动态密码"
						}
					}
				}, {
					"id": "smsloginmodel-mobile",
					"name": "SmsLoginModel[mobile]",
					"attribute": "mobile",
					"rules": {
						"match": {
							"pattern": /^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$|17[0-9]{1}[0-9]{8}$|14[0-9]{1}[0-9]{8}$/,
							"not": false,
							"skipOnEmpty": 1
						},
						"messages": {
							"match": "请输入一个有效的手机号码"
						}
					}
				}, {
					"id": "smsloginmodel-rememberme",
					"name": "SmsLoginModel[rememberMe]",
					"attribute": "rememberMe",
					"rules": {
						"boolean": {
							"trueValue": "1",
							"falseValue": "0"
						},
						"message": {
							"boolean": "记住用户名密码的值必须要么为\"1\"，要么为\"0\"。"
						}
					}
				}, {
					"id": "smsloginmodel-captcha",
					"name": "SmsLoginModel[captcha]",
					"attribute": "captcha",
					"rules": {
						"required": true,
						"messages": {
							"required": "请输入图片验证码"
						}
					}
				}, {
					"id": "smsloginmodel-captcha",
					"name": "SmsLoginModel[captcha]",
					"attribute": "captcha",
					"rules": {
						"captcha": {
							"hash": 427,
							"hashKey": "niiCaptcha/site/captcha",
							"caseSensitive": false
						},
						"messages": {
							"captcha": "验证码不正确。"
						}
					}
				}, ]
			</script>
			<script type="text/javascript">
				$().ready(function() {

					//二维码、PC登录切换
					$('.qrcode-target').click(function() {
						if($(this).hasClass('btn-qrcode')) {
							$(this).removeClass('btn-qrcode').addClass('btn-login').attr('title', '去电脑登录');
							$('.login-wrap').hide();
							$('.login-mobile').show();
							return;
						}
						if($(this).hasClass('btn-login')) {
							$(this).removeClass('btn-login').addClass('btn-qrcode').attr('title', '去手机扫码登录');
							$('.login-wrap').show();
							$('.login-mobile').hide();
						}
					});

					$("body").on('click', '.website-login', function() {
						var type = $(this).data("id");
						$.go("http://user.ymcc.com" + "/website/login?type=" + type);
					})

					var container = $("#14849678895bBEJL");

					/**
					 * 初始化validator默认值
					 */
							//先获取到默认函数，不能直接覆盖掉
					var errorPlacement = $.validator.defaults.errorPlacement;
					$.validator.setDefaults({
						errorPlacement: function(error, element) {
							$(element).parent(".form-control-box").addClass("error");
							errorPlacement.call(this, error, element);
						},
						// 失去焦点验证
						onfocusout: function(element) {
							$(element).valid();
						},
						// 成功后移除错误提示
						success: function(error) {
							var error_id = $(error).attr("id");
							var element_id = $(error).attr("for");
							// 移除错误样式
							$("[id='" + error_id + "']").remove();
							$(":input[id='" + element_id + "']").parent(".form-control-box").removeClass("error");
						}
					});

					var validator = $(container).find("#form2").validate();
					// 验证规则，此验证规则会影响编辑器中JavaScript的的格式化操作
					$.validator.addRules($("#client_rules").html());

					$(container).find("#form2").submit(function() {

						if(!validator.form()) {
							return false;
						}
						return true;
					});

					var validator1 = $(container).find("#form1").validate();
					// 验证规则，此验证规则会影响编辑器中JavaScript的的格式化操作
					$.validator.addRules($("#sms_client_rules").html());

					$(container).find("#form1").submit(function() {
						if(!validator1.form()) {
							return false;
						}
						return true;
					});

					$(container).find("#btn_send_sms_code").click(function() {

						if($(this).prop("disabled") == true || $(this).data("doing") == true) {
							return;
						}

						var mobile_valid = $("#mobile").valid();
						var captcha_valid = true;
						if($("#captcha_sms").size() > 0) {
							captcha_valid = $("#captcha_sms").valid();
						}

						if(mobile_valid && captcha_valid) {

							var target = this;

							$(this).data("doing", true);

							var mobile = $("#mobile").val();

							$.post('/site/sms-captcha', {
								mobile: mobile,
								captcha: $("#captcha_sms").val()
							}, function(result) {
								if(result.code == 0) {
									// 开始倒计时
									countdown(target, "获取手机动态验证码");
								} else {
									// 失败后点击验证码
									if($("#captcha_sms-image").size() > 0) {
										$("#captcha_sms").val("");
										$("#captcha_sms-image").click();
									}
									var errors = {};
									errors["SmsLoginModel[" + result.data + "]"] = result.message;
									validator1.showErrors(errors);
								}
								$(target).data("doing", false);
							}, "json");
						}

					});

					var wait = 60;

					function countdown(obj, msg) {
						obj = $(obj);

						if(wait <= 0) {
							obj.prop("disabled", false);
							obj.html(msg);
							wait = 60;
						} else {
							if(msg == undefined || msg == null) {
								msg = obj.html();
							}
							obj.prop("disabled", true);
							obj.html(wait + "秒后重新获取");
							wait--;
							setTimeout(function() {
								countdown(obj, msg)
							}, 1000)
						}
					}
				});
			</script>

		</div>
	</div>
</div>

<!-- 底部 -->

<!-- 底部 _end-->

</body>
<script src="/js/axios.common.js"></script>

<script>
	$().ready(function() {
		new Vue({
			el:"#login-wrap",
			data(){
				return {
					formParams:{
						phone:'13330964748',
						password:'123'
					}
				}
			},
			methods:{
				submitLogin:function () {
					console.log($("#loginsubmit"));
					$("#loginsubmit").val("登录中...");
					$("#loginsubmit").attr("disabled",true);
                    var username = this.formParams.phone;
                    var password = this.formParams.password;
					//拼接获取tokne的参数
					var loginParams = {
						username: username,
						password: password ,
						type:1  //后台用户
					};

					//发起请求
					this.$http.post("/uaa/login/common",loginParams).then(res=>{

						let {success , data,message} = res.data;

                        //获取到Token
						if(success){
							$.alert("登录成功");
							var token = data.access_token;
							var refresh_token = data.refresh_token;
							$.cookie('U-TOKEN',token,{
								expires:7,
								path:'/',
								domain:'ymcc.com',
								secure:false
							});
							$.cookie('R-TOKEN',refresh_token,{
								expires:7,
								path:'/',
								domain:'ymcc.com',
								secure:false
							});

							var userJSON = {"username":username};
							var userStr = JSON.stringify(userJSON);
							$.cookie('user',userStr,{
								expires:7,
								path:'/',
								domain:'ymcc.com',
								secure:false
							});


							let callUrl = api.getCallUrl();
							if(callUrl){
								window.location.href = callUrl;
							}else{
								window.location.href="http://user.ymcc.com:6003/user.home.html"
							}
						}else{
							$.alert("登录失败["+message+"]");
						}
						$("#loginsubmit").attr("disabled",false);
						$("#loginsubmit").val("立即登录");

                    }).catch(error => {
                        $.alert("登录失败["+error.message+"]");
						$("#loginsubmit").attr("disabled",false);
						$("#loginsubmit").val("立即登录");
                    });
				}
			},
			mounted(){
			}
		});
	});

</script>
</html>
